home *** CD-ROM | disk | FTP | other *** search
- /*
- Example.c
-
- Example extension. Demonstrates use of PatchWorks trap patching
- system to patch MenuSelect. Uses new GenericPatch class.
-
- by Mouse Herrell & Patrick Beard.
-
- © 1991 Berkeley Systems Inc.
- */
-
- #include <string.h>
- #include <Notification.h>
- #include <Traps.h>
- #include <stdarg.h>
- #include <stdio.h>
- #include <stddef.h>
- #include <Events.h>
- #include <Strings.h>
- #include <strstream.h>
-
- #include "ShowIconFamily.h"
- #include "Exceptions.h"
- #include "Extension.h"
- #include "Example.h"
-
- MenuSelectPatch::MenuSelectPatch()
- {
- itsCallCount = 0;
- GenericPatch::InitGenericPatch(_MenuSelect, offsetof(MenuSelectParameters, itsResult));
- Install();
- }
-
- void MenuSelectPatch::Behavior()
- {
- KeyMap Keys;
-
- // announce our presence & abort the trap if control key held down.
- ++itsCallCount;
- GetKeys(Keys);
- if (Keys[1] & 0x8) {
- MenuSelectParameters* params = (MenuSelectParameters*)itsFrame->parameters;
- params->itsResult = 0;
- AbortTrap();
- strstream message;
- Point& pt = params->itsStartPt;
- message << "MenuSelect: startPt = (" << pt.h << ", " << pt.v << "), " << itsCallCount << " calls." << '\0';
- debugstr(message.str());
- }
- }
-
- void Install()
- {
- try {
- // if extension succeeds, show happy icon.
- new MenuSelectPatch;
- ShowIconFamily(128);
- } catch {
- // extension failed, show sad icon.
- ShowIconFamily(129);
- throw(theException);
- }
- }
-
- // called when system is shutdown.
-
- void Remove()
- {
- Patch::RemoveAll();
- }
-